#include "localtcpser.hpp"
#include "protocol.hpp"

#define UNIQUE_TCPSER std::unique_ptr<Local_TcpSer::TcpServer>
#define MAKE_UNIQUE_TCPSER std::make_unique<Local_TcpSer::TcpServer>
#define UNIQUE_SOCKET std::shared_ptr<Local_Sock_Mod::Socket>
#define LOCAL_INETADDR Local_Inetaddr::Inetaddr

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        SerErr();
        exit(ERR_SER);
    }
    uint16_t tcp_port = std::stoi(argv[1]);

    // 启动协议
    Protocol ma_pro;

    // 创建服务器
    UNIQUE_TCPSER ma_tcpser = MAKE_UNIQUE_TCPSER(tcp_port,
                                                 [&ma_pro](UNIQUE_SOCKET &sockfd, LOCAL_INETADDR &client)
                                                 {
                                                     ma_pro.GetRequest(sockfd, client);
                                                 });

    // std::unique_ptr<Local_TcpSer::TcpServer> ma_tcpser = std::make_unique<Local_TcpSer::TcpServer>(tcp_port,
    //                                                                                                [&ma_pro](std::shared_ptr<Local_Sock_Mod::Socket> &sockfd, Local_Inetaddr::Inetaddr &client)
    //                                                                                                {
    //                                                                                                    ma_pro.GetRequest(sockfd, client);
    //                                                                                                });
    ma_tcpser->start();

    return 0;
}